pkg_name=mudev
git_commit=506bf3cdb48adefd6ec78e673c467c0297092b67
build_dir=$builds_dir_root/$pkg_name
pkg_dir=$pkgs_dir_root/$pkg_name
src_dir=$src_dir_root/$pkg_name
url=https://github.com/sylware/$pkg_name.git

rm -Rf "$pkg_dir"
cp -r "$src_dir" "$pkg_dir"

cd "$pkg_dir"

git checkout --force $git_commit
git reset --hard

rm -Rf "$build_dir"
mkdir -p "$build_dir"
cd "$build_dir"

"$src_dir/make" --prefix=/

install_tmp_dir=/tmp/$pkg_name
rm -Rf "$install_tmp_dir"
mkdir -p "$install_tmp_dir"

mkdir -p "$install_tmp_dir/bin"
mkdir -p "$install_tmp_dir/lib"
mkdir -p "$install_tmp_dir/lib/pkgconfig" 
mkdir -p "$install_tmp_dir/lib/udev"
mkdir -p "$install_tmp_dir/include"
cp -f "$build_dir/fake_root/lib/libudev.so.0.0.0" "$install_tmp_dir/lib"
ln -sf libudev.so.0.0.0 "$install_tmp_dir/lib/libudev.so.0"
ln -sf libudev.so.0 "$install_tmp_dir/lib/libudev.so"
cp -f "$build_dir/fake_root/include/libudev.h" "$install_tmp_dir/include"
cp -f "$build_dir/fake_root/lib/pkgconfig/libudev.pc" "$install_tmp_dir/lib/pkgconfig"
cp -f "$build_dir/fake_root/lib/pkgconfig/udev.pc" "$install_tmp_dir/lib/pkgconfig"
#those are the system rules, see doc for rule precedence
cp -rf "$build_dir/fake_root/lib/udev/rules.d" "$install_tmp_dir/lib/udev"
cp -f "$build_dir/fake_root/sbin/udevadm" "$install_tmp_dir/bin"
cp -f "$build_dir/fake_root/sbin/udevd" "$install_tmp_dir/bin"

install_dirs "$builders_dir_root/$pkg_name/runtime.dirs"
install_files "$builders_dir_root/$pkg_name/runtime.files" "$install_tmp_dir"
install_links "$builders_dir_root/$pkg_name/runtime.links"
install_dirs "$builders_dir_root/$pkg_name/devel.dirs"
install_files "$builders_dir_root/$pkg_name/devel.files" "$install_tmp_dir"
install_links "$builders_dir_root/$pkg_name/devel.links"
elf_strip "$builders_dir_root/$pkg_name/elf-strip"

rm -Rf "$install_tmp_dir"
rm -Rf "$build_dir"
rm -Rf "$pkg_dir"
